package com.frontop.system.modules.user.controller;


import com.alibaba.fastjson.JSONArray;
import com.frontop.common.util.ResultJsonUtil;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * <p>
 *  字典前端控制器
 * </p>
 *
 * @author YangJia
 * @since 2021-09-16
 */
@RestController
@RequestMapping("/sys-dict")
public class SysDictController {
    @Autowired
    private RedisTemplate redisTemplate;

    @ApiOperation(value = "根据类型获取字典列表")
    @GetMapping("/getDictList/{type}")
    public ResultJsonUtil<Object> getDictList(@PathVariable("type") String type, HttpServletRequest request) {

        Map<String, String> resultMap= redisTemplate.opsForHash().entries("dict");
        return new ResultJsonUtil().success(JSONArray.parseArray(resultMap.get(type)));
    }
}